<?php

Raise::load('core.ui.RaisePage');

/**
 * RaiseOAuthUserAuthLangingPage class
 * Step C - D
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.library.oauth.page
 * @since 1.2
 */
abstract class RaiseOAuthUserAuthLangingPage extends RaisePage{
    
    function __construct() {
        parent::__construct('$output$');
    }
    
    /**
     * after user is redirected from Consumer to Service Provider
     * the login is initiated, then confirmation of this consumer, then
     * redirect user back to consumer using callback URL
     */
    
    public function build() {
        
        // receive token
        
        if(!$this->checkUserLoggedIn()){
            $this->application()->response()->redirect($this->userSignInUrl());
        }
        
        if(!$this->checkUserAuthorization()){
            $this->application()->response()->redirect($this->userSignInUrl());
        }
        
    }
    
    /**
     * Return the URL for the user login page.
     * @return RaiseUrl|string
     */
    abstract function userSignInUrl();
    
    /**
     * Check if the user is logged in already.
     * @return boolean Return TRUE if already logged in, FALSE otherwise.
     */
    abstract function checkUserLoggedIn();
    
    /**
     * Return the URL for the user authorization page.
     * @return RaiseUrl|string
     */
    abstract function userAuthorizationUrl();
    
    /**
     * Check if the user has authorized the use of this applicatonion
     * @return boolean Return TRUE if user has already authorized the application to use his/her data, FALSE otherwise.
     */
    abstract function checkUserAuthorization();

    
}
